#ifndef DREAM_H
#define DREAM_H

#include <QListWidget>
#include "Crypter.h"
#include "Requests.h"
#include "PeopleWindow.h"
class ChatWindow;
class Satory;
struct ChatKey;

class Dream:public QObject
{
    Q_OBJECT

    Satory* Master;
    QString mName;
    Crypter mSender,mReceiver;
    bool isAlive,isAuth;
   // void SaveKey(DataBlock& key,const std::string& type);
//    bool LoadKey(DataBlock& key,const std::string& type);
    enum DreamState{NONE=0,ASK_AUTH,CONFIRM_AUTH,CHAT_KEY}mState;
    bool isInitSender,isInitReceiver;
    void GenChatKey(ChatKey& key);
    bool AcceptChatKey(ChatKey& sender,ChatKey& receiver);
    QListWidgetItem* mItem;
    ChatWindow* mChat;

    list<QString> msgToSend;
    list<pair<quint64,DataBlock> > msgToAccept;
    quint64 mMessageCounter;
public:
    enum UiType{PERSON,CHAT};
    Dream(Satory* master,QString name);
    void AttachUi(UiType type, void* attach);
    QString GetName(){return mName;}

    bool AskAuth();
    bool ConfirmAuth();
    void SetAuthStatus(bool val);

    void SendMessage(QString msg);
    void AcceptMessage(DataBlock& msg,quint64 counter);
    void UpdateMessages();


public slots:
    void OnRequestArrived(BaseRequest* request,Json::Value& answer);

};

#endif // DREAM_H
